import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 沈明月
 * Date: 2022-11-02
 * Time: 21:57
 */
public class TestFourteen {
//模拟登陆:
//编写代码模拟三次密码输入的场景
//最多能输入三次密码，密码正确，提示“登录成功”,密码错误，
//可以重新输入，最多输入三次。三次均错，则提示退出程序
    public static void main1(String[] args) {
        //设定一个密码：
        int s = 462781;

        //开始输入密码：
        System.out.println("请输入密码：");
        Scanner scanner = new Scanner(System.in);
        int m = scanner.nextInt();
        if(m == s){
            System.out.println("登陆成功");
        }else{
            int n = 2;
            while(n != 0){
                System.out.println("密码错误，请重新输入");
                m = scanner.nextInt();
                if(m == s){
                    System.out.println("登陆成功");
                    break;
                }
                n--;
            }
        }
        if(m != s){
            System.out.println("密码输入次数已耗尽");
        }
    }

    public static void main2(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int count = 3;

        while (count != 0) {
            System.out.println("请输入你的密码：");
            String password = scanner.nextLine();

            //if(password == "123") { 这个判断相等是错误的，具体原因后续String章节进行讲解

            if(password.equals("123")) {
                System.out.println("登录成功！");
                break;
            }else {
                count--;
                System.out.println("你还有"+count+" 次机会！");
            }
        }
    }
}
